<template>
  <!-- 歌词 -->
  <div id="lyrivc">
    <van-list v-model="loading"
              :finished="finished"
              offset="10"
              finished-text="没有更多了"
              @load="onLoad">
      <van-grid :column-num="1">
        <van-grid-item v-for="(song, index) in songList"
                       :key="index">
          <template #icon>
            <van-cell :title="song.name">
              <template #label>
                <template v-if="song.ar.length > 1">
                  <span v-for="(ar, idx) in song.ar"
                        :key="idx">
                    {{ idx == song.ar.length - 1 ? ar.name : ar.name + "," }}
                  </span>
                </template>
                <template v-else>
                  <span>{{ song.ar[0].name + " - " + song.al.name }}</span>
                </template>
              </template>
            </van-cell>
          </template>
          <template #text>
            <van-collapse v-model="activeNames"
                          :accordion="true">
              <van-collapse-item :name="index">
                <template #title>
                  <p v-for="(lyrics,idx) in song.lyrics.slice(0,3)"
                     :key="idx"
                     v-html="lyrics" />
                </template>
                <p v-for="(lyrics,idx) in song.lyrics.slice(3,song.lyrics.length)"
                   :key="idx">{{lyrics}}</p>
              </van-collapse-item>
            </van-collapse>
          </template>
        </van-grid-item>
      </van-grid>
    </van-list>
  </div>
</template>

<script>
import { getSearch } from '@/api/search'
export default {
  name: 'lyrivc',
  data() {
    return {
      loading: true,
      finished: false,
      rowText: '',
      limit: 15,
      type: 1006,
      songList: [],
      activeNames: ['1'],
    }
  },
  methods: {
    onLoad() {
      this.limit + 5
    },
    initData() {
      getSearch(
        this.rowText,
        this.limit,
        this.type,
        this.$store.state.userInfo.cookie
      ).then((res) => {
        this.songList = res.result.songs
        this.loading = false
      })
    },
  },
}
</script>

<style scoped>
#lyrivc /deep/ .van-grid-item__icon-wrapper,
#lyrivc /deep/ .van-hairline--top-bottom {
  width: 100%;
}
</style>